package com.demo.house.service.impl;

import com.demo.house.dao.HouseSourseDao;
import com.demo.house.dao.HouseUrlDao;
import com.demo.house.entity.HouseSourse;
import com.demo.house.entity.HouseUrl;
import com.demo.house.service.HouseUrlSourseService;
import com.demo.house.vo.RequestVo.HouseUrlSourseVo;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.ArrayList;
import java.util.List;

@Service
public class HouseUrlServicelmpl  implements HouseUrlSourseService {

    @Autowired
    private HouseSourseDao houseSourseDao;
    private final String uploadPath="D:\\img\\";
    @Autowired
    private HouseUrlDao houseUrlDao;


    /**
     * 连表查询
     * @param id
     * @return
     */
    @Override
    public List<HouseUrlSourseVo> queryById(Integer id) {
        HouseSourse houseSourse = houseSourseDao.selectByPrimaryKey(id);
        HouseUrl houseUrl = houseUrlDao.selectByPrimaryKey(houseSourse.getId());
        List<HouseUrlSourseVo> list = new ArrayList<>();
        HouseUrlSourseVo houseUrlSourseVo = new HouseUrlSourseVo();
        houseUrlSourseVo.setId(houseUrl.getId());
        houseUrlSourseVo.setTitle(houseSourse.getTitle());
        houseUrlSourseVo.setState(houseSourse.getState());
        houseUrlSourseVo.setPrice(houseSourse.getPrice());
        houseUrlSourseVo.setAddress(houseSourse.getAddress());
        houseUrlSourseVo.setHouseType(houseSourse.getHouseType());
        list.add(houseUrlSourseVo);
        return list;
    }
    /*图片显示*/
    @SneakyThrows
    @Override
    public BufferedImage getImg(Integer id) {
        HouseUrl byid = houseUrlDao.getByid(id);
        System.out.println(byid);

        String path = uploadPath+byid.getUrl();
        System.out.println(path);
        File file = new File(path);
        BufferedImage read = ImageIO.read(file);
        return read;
    }




}
